package com.hejjon.controller;

import com.hejjon.core.bean.ResponseResult;
import com.hejjon.core.controller.BaseController;
import com.hejjon.domain.request.LibraryDataQueryRequest;
import com.hejjon.domain.request.LibraryDataRequest;
import com.hejjon.service.ILibaryDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Api(tags = "知识库数据")
@RestController
@RequestMapping("/library/data")
public class LibraryDataController extends BaseController {


    @Resource
    private ILibaryDataService libaryDataService;


    @ApiOperation(value = "知识库数据表格")
    @PostMapping("/listDataTable")
    public ResponseResult listDataTable() {

        return success();
    }


    @ApiOperation(value = "批量保存知识数据")
    @PostMapping("/batchSave")
    public ResponseResult batchSave(@RequestBody LibraryDataRequest req) {
        int rows = libaryDataService.batchSave(req);
        return toResult(rows, "知识数据保存成功,记录条数: " + rows);
    }


    @ApiOperation(value = "知识数据列表查询")
    @PostMapping("/queryDataList")
    public ResponseResult queryDataList(@RequestBody LibraryDataQueryRequest request) {
        return success(libaryDataService.queryDataList(request));
    }


    @ApiOperation(value = "批量删除(逻辑删除)数据")
    @PostMapping("/batchRemove")
    public ResponseResult batchRemove(@RequestBody LibraryDataRequest request) {
        int cnt = libaryDataService.logicDelte(request);
        return toResult(cnt, "成功删除" + cnt + "条记录");
    }


    @ApiOperation(value = "下载模板")
    @GetMapping("/downloadTemplate")
    public ResponseEntity<byte[]> downloadTemplate(@RequestParam String recordId, @RequestParam String featureId) {

        return libaryDataService.downloadTemplate(recordId, featureId);
    }


    @ApiOperation(value = "批量导入数据")
    @PostMapping("/batchImport")
    public ResponseResult batchImport(MultipartFile file, @RequestParam String nodeId) {

        return success();
    }



}
